/**
 * Created by yqj on 2017/2/16.
 */

const config = require('../config/mongodb-config.js'),
    mongoose = require('mongoose');

/**
 * 连接数据库
 */
const db = mongoose.connect(`mongodb://localhost:27017/${config.database}`);

/**
 * 连接成功
 */
mongoose.connection.on('connected', function () {
    console.log(`Mongoose connection open to mongodb://localhost:27017/${config.database}`);
});

/**
 * 连接异常
 */
mongoose.connection.on('error',function (err) {
    console.log('Mongoose connection error: ' + err);
});

/**
 * 连接断开
 */
mongoose.connection.on('disconnected', function () {
    console.log('Mongoose connection disconnected');
});

module.exports = mongoose;